const mongoose = require('mongoose')

const schema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    unique: true,
  },
  author: {
    type: String,
    default: '佚名',
  },
  price: Number,
  status: {
    type: String,
    enum: ['上架', '下架'],
  },
  is_hot: Boolean,
  tags: Array,
  create_time: Date,
  notes: mongoose.Schema.Types.Mixed,
})

// book单词书写为单数时，在数据库创建集合时会自动变为复数books
const mongooseModule = mongoose.model('book', schema)

module.exports = mongooseModule